<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="resultList" border>
      <el-table-column align="center" label="项目名称" prop="projectName"/>
      <el-table-column align="center" label="所属主题" prop="degreetitleName"/>
      <el-table-column v-if="type==2" align="center" label="客户名称" prop="userName"/>
      <el-table-column v-if="type==1" align="center" label="员工名称" prop="staffName"/>
      <el-table-column align="center" label="综合评分" prop="score"/>
      <el-table-column align="center" label="满意度">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.score < 1" type="danger">不满意</el-tag>
          <el-tag v-if="scope.row.score >=1 && scope.row.score < 3">满意</el-tag>
          <el-tag v-if="scope.row.score >=3 && scope.row.score < 4">比较满意</el-tag>
          <el-tag v-if="scope.row.score == 5">非常满意</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button  size="mini" type="text"
                     @click="handleView(scope.row)">查看
          </el-button>
          <!-- <el-button size="mini" type="text"  @click="handleDelete(scope.row)"
            v-hasPermi="['cld:result:remove']">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
                @pagination="getList"/>

    <!-- 添加或修改满意度结果对话框 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="open" append-to-body title="查看结果" width="500px">
      <el-form ref="form" :model="form" label-position="top" label-width="80px">
        <el-form-item v-for="item in form.problemList" :key="item.degreetitleProblemId"
                      :label="item.degreetitleProblemName">
          {{ item.result.score }}分
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {delResult, listResult, selectSurveryDetails} from "@/api/cld/degreetitle";

export default {
  name: "Result",
  props: {
    type: {
      type: Number
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 满意度结果表格数据
      resultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params: {
          isGroup: '1',
          degreetitleType: this.type
        }

      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询满意度结果列表 */
    getList() {
      this.loading = true;
      listResult(this.queryParams).then(response => {
        this.resultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        degreetitleResultId: null,
        projectId: null,
        personId: null,
        degreetitleId: null,
        degreetitleProblemId: null,
        score: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看
    handleView(row) {
      this.reset();
      selectSurveryDetails({
        personId: row.personId,
        projectId: row.projectId,
        degreetitleId: row.degreetitleId
      }).then(res => {
        this.form = res.data;
        this.open = true;
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const degreetitleResultIds = row.degreetitleResultId || this.ids;
      this.$modal.confirm('是否确认删除满意度结果编号为"' + degreetitleResultIds + '"的数据项？').then(function () {
        return delResult(degreetitleResultIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
  }
};
</script>
